#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>


void handle(int sig)
{
	printf("信号捕获开始\n");
	if(sig == SIGINT)
	{
		printf("捕获到了的信号是%d\n", sig);
	}else if(sig == SIGALRM)
	{
		printf("捕获到的是SIGALRM信号\n");
	}

}


int main()
{
	struct sigaction act;			//定义sigaction结构体
	act.sa_handler = handle;		//初始化结构体
	act.sa_flags = 0;
	sigemptyset(&act.sa_mask);

	//定时器
	struct itimerval value;		      //定义itimerval结构体
	value.it_interval.tv_sec = 1;	  //闹钟触发周期 (秒)
	value.it_interval.tv_usec = 0;	  //闹钟触发周期 (微妙)
	
	value.it_value.tv_sec = 5;		  //闹钟触发时间(秒)
	value.it_value.tv_usec = 0;		  //闹钟触发时间(微妙)

	setitimer(ITIMER_REAL, &value, NULL);

	sigaction(SIGALRM, &act, NULL);   //捕捉SIGALRM
	sigaction(SIGINT, &act, NULL);   //信号捕捉

	while(1)
	{
		sleep(1);
	}
}



















